<template>
	<view>
		<view style="padding:20rpx">私密视频</view>
		<view style="padding:20rpx;">
			<fui-upload immediate :url="uploadUrl" ref="upload" :fileList="fileList" width="200" height="200"
				@success="uploadSuccess" @error="uploadError" @complete="uploadComplete" Right></fui-upload>
		</view>
		<button class="submitBtn" @click="savePhoto">保存</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				uploadUrl: 'https://api.meimo.comdns.cn/common/Upload/upload?file=uservideo&type=video',
				uploadStatus: {},
				fileList: [],
				uploadUrls: []
			};
		},
		onLoad() {
			this.getPhoto();
		},
		methods: {
			getPhoto() {
				this.$httpost('/UserAction/getMyVideo', {}).then(res => {
					if (res.code == 200) {
						if (JSON.parse(res.data.UserVideos) != null) {
							this.uploadUrls = JSON.parse(res.data.UserVideos)
							this.fileList = this.uploadUrls
						}
					}
				});
			},
			uploadSuccess(e) {
				// console.log(e)
				//e.res 为服务器返回数据
				//上传成功回调，处理服务器返回数据【此处根据实际返回数据进行处理】
				let res = JSON.parse(e.res.data.replace(/\ufeff/g, "") || "{}")
				this.uploadStatus = e.status
				if (res.fileName) {
					//处理结果返回给组件 
					//res.data.url为上传成功后返回的图片地址
					//e.index为图片索引值
					this.$refs.upload.result(this.$baseUrl + res.fileName, e.index)
				}
			},
			uploadComplete(e) {
				this.uploadStatus = e.status
				this.uploadUrls = e.urls
				if (this.uploadStatus === 'success' && e.action === 'upload') {
					// this.fui.toast('上传完成！')
					//已上传完成的图片列表 this.urls
					// console.log('this.this.uploadUrls', this.uploadUrls)
				}
			},
			uploadError(e) {
				this.uploadStatus = e.status
			},
			savePhoto() {
				this.$httpost('/UserAction/saveMyVideo', {
					uploadUrls: this.uploadUrls
				}).then(res => {
					if (res.code == 200) {
						this.$common.goNavPage('/myPages/pages/mypage?artisterID=' + res.data.UserID)
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	.submitBtn {
		background-color: $globalColor;
		color: #000;
		font-size: 28rpx;
		border: 0rpx solid $globalColor;
		width: 80vw;
		height: 80rpx;
		line-height: 80rpx;
		margin: auto
	}
</style>